<template>
	<!-- 首页门店详情 -->
	<view class="pageBgV">
		<u-navbar :bgColor="bgColor" title=" " @leftClick="onBackClick" :titleStyle="titleStyle" leftIconColor="#fff">

		</u-navbar>
		<view class="bgV">
			<view class="topIv">
				<u-swiper :list="detailsData.images" :autoplay="true" indicatorStyle="right: 20px" height="450rpx"
					radius="0" circular>
				</u-swiper>
			</view>
			<view class="centV">
				<view class="titleV">
					<view class="titleTv">{{detailsData.name}}</view>
					<!-- <image @click="onCollectionClick()" class="guanzhuIv"
						:src="true?'../../static/public/collection_to.svg':'../../static/public/collection.svg'">
					</image> -->
					<view @click="onShareClick()" class="shareV">
						<image class="shareIv" src="../../static/public/share.svg"></image>
						<button v-if="detailsData" class="shareTv" open-type="share">分享有礼</button>
					</view>
				</view>
				<view class="gpsV">
					<image class="gpsIv" src="../../static/public/gps.svg"></image>
					<view class="gpsTv">{{detailsData.address}}</view>
					<view class="mapV" @click="onMapClick(detailsData)">
						<image class="mapIv" src="../../static/public/ditu.svg"></image>
						<view class="mapTv">地图</view>
					</view>
					<!-- <view class="mapV">
						<image class="mapIv" src="../../static/public/jiaotong.svg"></image>
						<view class="mapTv">交通</view>
					</view> -->
				</view>
				<view class="gpssTv">{{detailsData.address_detail}}</view>
				<view class="itemTitleTv">团课</view>
				<view class="timeBg">
					<view class="itemTimeV" v-for="(item,key) in dayList" :key="key">
						<view :class="key==dayListPos?'timeTv':'timeTvTo'">{{item.day}}</view>
						<view :class="key==dayListPos?'dayTv':'dayTvTo'" @click="onSelectTimeClick(item,key)">{{item.week}}
						</view>
					</view>
				</view>
				<view class="contentV">
					<view class="typeBg">
						<view class="typeItemBg" v-if="contentList.length>0"  v-for="(data,indexs) in contentList" :key="indexs" @click="onItemClick(data)">
							<image class="typeIv" :src="data.image" mode="aspectFill"> </image>
							<view class="typeRightV">
								<view class="typeTitleTv">{{data.title}}</view>
								<view class="typeBottomV">
									<view class="centerV">
										<view class="timeMoney">
											<view class="timeTv">{{data.time}}</view>
											<view class="moneyTv">¥{{data.price}}</view>
										</view>
										<text class="labelTv" v-for="(txt,pos) in data.target">{{txt}}</text>
									</view>
									<view v-if="data.is_yuyue!=1" class="typeBookingTv">预约</view>
									<view v-if="data.is_yuyue==1" class="typeBookingTvTo">已预约</view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view v-if="mShopCoachList" class="itemTitleTv">私教专区</view>
				<view v-if="mShopCoachList" class="listV">
					<scroll-view class="scrV" scroll-x="true">
						<view @tap="onItemCoachClick(items)" class="itemV" v-for="(items,keys) in mShopCoachList" :key="keys">
							<view class="itemBg">
								<image class="avatarIv" :src="items.avatar"></image>
								<view class="nameTv">{{items.name}}</view>
								<view class="typeTv">{{items.motto}}</view>
								<view v-if="items.price" class="moneyTv">{{items.price}}起/课时</view>
								<view v-else class="moneyTv">--</view>
							</view>
						</view>
					</scroll-view>
				</view>
				<view v-if="mShopCampList" class="itemTitleTv">训练营</view>
				<view v-if="mShopCampList" class="listV">
					<u-grid col="2">
						<u-grid-item v-for="(itemCamp,keyCamp) in mShopCampList" :key="key">
							<view class="itemCampV" @tap="onItemCampClick(itemCamp)">
								<image class="itemCampIv" :src="itemCamp.image" mode="aspectFill"></image>
								<view class="itemCampTv">{{itemCamp.title}}</view>
							</view>
						</u-grid-item>
					</u-grid>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				titleStyle: {
					"color": "#ffffff"
				},
				bgColor: "#00000000",
				scrollTop: 0,
				shopId:'',
				detailsData:null,//店铺详情
				dayList:undefined,//日历
				dayListPos:0,
				dayData:'',
				contentList:[],//团课列表
				mShopCoachList: undefined,//私教专区
				mShopCampList: undefined,//训练营
			}
		},
		onShareAppMessage: function(res) {
			console.log("开始分享接收参数--->" + JSON.stringify(res))
			let shopId = this.shopId;
			return {
				title: this.detailsData.title,
				path: `mine/home/FitnessStore?id=` + shopId, // 分享后打开的页面
				success: function(res) {
					console.log("转发成功")
				},
				fail: function(res) {
					console.log("转发失败")
				}
			}
		},
		onLoad(e) {
			this.shopId = e.id;
			this.getStoresDetails();
			this.getShopComboList();
			this.getShopCoachList();
			this.getShopCampList();
			
		},
		onPullDownRefresh() {
			this.getStoresDetails();
			this.getShopComboList();
			this.getShopCoachList();
			this.getShopCampList();
		},
		onPageScroll(e){
			if(e.scrollTop>20){
				this.bgColor = "#FFFFFF";
			}else{
				this.bgColor = "#00000000";
			}
		},
		methods: {
			onBackClick() {
				let pages = getCurrentPages();
				if (pages[pages.length - 2]) {
					//如果有上一页，就返回上一页
					wx.navigateBack({
						delta: 1
					})
				} else {
					uni.switchTab({
						url: '/pages/app/Home'
					});
				}
			},
			getStoresDetails() { //获取门店详情
				this.$api.getStoresDetails({
					shop_id: this.shopId
				}).then((res) => {
					this.detailsData = res.info;
					uni.stopPullDownRefresh();
				}).catch((e) => {
					uni.stopPullDownRefresh();
					uni.$u.toast(e.msg === undefined ? "获取信息失败" : e.msg)
				})
			},
			onMapClick(item) {
				uni.authorize({
					scope: 'scope.userLocation',
					success() {
						uni.openLocation({
							longitude: parseFloat(item.longitude),
							latitude: parseFloat(item.latitude),
							name: item.shop_name, //位置名
							address: "", //详细地址
							success: function(res) {
								// console.log('位置名称：' + res.name);
								// console.log('详细地址：' + res.address);
								// console.log('纬度：' + res.latitude);
								// console.log('经度：' + res.longitude);
							},
							fail(res) {
								console.log("=====" + JSON.stringify(res))
							}
						});
					},
					fail() {
						uni.showModal({
							title: '未打开小程序定位',
							content: '找不到您的位置，请开启定位',
							confirmText: '开启定位',
							showCancel: false,
							success: (res) => {
								if (res.confirm) {
									uni.openSetting(); // 打开地图权限设置
								}
							}
						});
					}
				})
			},
			// onCollectionClick(){// 收藏
			// 	this.$api.addCollection({
			// 		type: "combo",
			// 		id: this.id
			// 	}).then((res) => {
			// 		this.getOrderDetails()
				
			// 	}).catch((e) => {
			// 		uni.$u.toast(e.msg === undefined ? "请求失败" : e.msg)
			// 	})
			// },
			getShopComboList() { //获取门店团课
				this.$api.getShopComboList({
					longitude: uni.getStorageSync("user_longitude"),
					latitude: uni.getStorageSync("user_latitude"),
					day:this.dayData,
					shop_id: this.shopId
				}).then((res) => {
					this.dayList = res.day7;
					this.contentList = res.list;
					if (this.dayData.length == 0 && this.dayList.length > 0){
						this.dayData = this.dayList[0].day;
						this.getShopComboList();
					}
				}).catch((e) => {
					
				})
			},
			onSelectTimeClick(item, key) {//选择团课时间
				this.dayListPos = key;
				this.dayData = item.day;
				this.getShopComboList();
			},
			onItemClick(item){//团课预约
				this.$u.route({
					url: '/pages/schedule/GroupDetails',
					params: {
						id: item.id,
					}
				})
			},
			getShopCoachList() { //获取门店私教
				this.$api.getShopCoachList({
					shop_id: this.shopId
				}).then((res) => {
					this.mShopCoachList = res;
				}).catch((e) => {
					
				})
			},
			onItemCoachClick(item){//私教详情
				this.$u.route({
					url: '/pages/schedule/TeachDetails',
					params: {
						id: item.id,
					}
				})
			},
			getShopCampList() { //获取门店训练营
				this.$api.getShopCampList({
					shop_id: this.shopId
				}).then((res) => {
					this.mShopCampList = res;
				}).catch((e) => {
					uni.$u.toast(e.msg === undefined ? "获取信息失败" : e.msg)
				})
			},
			onItemCampClick(item){//训练营点击
				this.$u.route({
					url: '/pages/schedule/BootcampDetails',
					params: {
						id: item.id,
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.pageBgV {
		display: flex;
		flex-direction: column;
		min-height: 100vh;
		height: auto;
	}

	.bgV {
		display: flex;
		flex-direction: column;
		height: 100%;
		flex: 1;
	}

	.topIv {
		width: 100%;
		height: 450rpx;
	}
	.centV{
		height: 100%;
		padding-bottom: 20rpx;
		flex: 1;
		border-top-left-radius: 10px;
		border-top-right-radius: 10px;
		margin-top: -10px;
		z-index: 1;
	}
	
	.titleV {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-left: 30rpx;
		padding-right: 30rpx;
		padding-top: 50rpx;
		box-sizing: border-box;
	
		.titleTv {
			color: #000000;
			font-size: 36rpx;
			max-width: 450rpx;
			min-width: 450rpx;
		}
	
		.guanzhuIv {
			width: 32rpx;
			height: 32rpx;
		}
	
		.shareV {
			display: flex;
			align-items: center;
	
			.shareIv {
				width: 32rpx;
				height: 32rpx;
			}
	
			.shareTv {
				margin-left: 5rpx;
				color: #979797;
				font-size: 28rpx;
				background-color: #00000000;
			}
	
			button::after {
				border: none;
			}
	
			button {
				position: relative;
				display: block;
				margin-left: auto;
				margin-right: auto;
				padding-left: 0px;
				padding-right: 0px;
				box-sizing: border-box;
				text-align: center;
				text-decoration: none;
				line-height: 1.35;
				-webkit-tap-highlight-color: transparent;
				overflow: hidden;
				color: #000000;
				background-color: #fff;
				width: 100%;
				height: 100%;
			}
		}
	}
	
	
	.gpsV {
		display: flex;
		align-items: center;
		margin-top: 20rpx;
		padding-left: 30rpx;
		padding-right: 10rpx;
	
		.gpsIv {
			width: 30rpx;
			height: 30rpx;
		}
	
		.gpsTv {
			flex: 1;
			color: #666666;
			font-size: 32rpx;
			margin-left: 23rpx;
		}
	
		.mapV {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			padding-left: 20rpx;
			padding-right: 20rpx;
	
			.mapIv {
				width: 32rpx;
				height: 32rpx;
			}
	
			.mapTv {
				margin-top: 1rpx;
				font-size: 24rpx;
				color: #8d8d8d;
			}
		}
	}
	
	.gpssTv {
		margin-top: 10rpx;
		margin-left: 83rpx;
		color: #8d8d8d;
		font-size: 24rpx;
	}
	
	.itemTitleTv{
		font-size: 32rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
		margin-top: 30rpx;
		padding-left: 30rpx;
	}
	
	.timeBg {
		height: 150rpx;
		display: flex;
	
		.itemTimeV {
			flex: 1;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
	
			.timeTv {
				font-size: 24rpx;
				color: #E6A5B4;
			}
	
			.timeTvTo {
				font-size: 24rpx;
				color: #939393;
			}
	
			.dayTv {
				width: 50rpx;
				height: 50rpx;
				border: 2px solid #E6A5B4;
				border-radius: 50%;
				font-size: 24rpx;
				color: #E6A5B4;
				display: flex;
				align-items: center;
				justify-content: center;
				margin-top: 20rpx;
			}
	
			.dayTvTo {
				width: 50rpx;
				height: 50rpx;
				border: 2px solid #E6A5B4;
				background-color: #E6A5B4;
				border-radius: 50%;
				font-size: 24rpx;
				color: #FFFFFF;
				display: flex;
				align-items: center;
				justify-content: center;
				margin-top: 20rpx;
			}
		}
	}
	
	.contentV {
		margin-top: 30rpx;
	}
	
	.typeBg {
		background: #1F1F1F;
		border-radius: 10rpx;
		margin-left: 30rpx;
		margin-right: 30rpx;
		margin-top: 10rpx;
	
		.typeItemBg {
			height: 198rpx;
			padding-left: 30rpx;
			padding-right: 30rpx;
			display: flex;
			align-items: center;
			justify-content: center;
	
			.typeIv {
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;
				background-color: #E6A5B4;
			}
	
			.typeRightV {
				flex: 1;
				margin-left: 20rpx;
	
				.typeTitleTv {
					font-size: 32rpx;
					color: #E8E8E8;
				}
	
				.typeBottomV {
					display: flex;
					align-items: center;
					justify-content: center;
	
					.centerV {
						flex: 1;
	
						.timeMoney {
							display: flex;
	
							.timeTv {
								color: #E6A5B4;
								font-size: 28rpx;
							}
	
							.moneyTv {
								color: #E6A5B4;
								font-size: 28rpx;
								margin-left: 30rpx;
							}
						}
	
						.labelTv {
							background: #4A4A4A;
							border-radius: 10rpx 0rpx 10rpx 0rpx;
							color: #9B9B9B;
							font-size: 22rpx;
							padding-left: 18rpx;
							padding-right: 18rpx;
							padding-top: 1rpx;
							padding-bottom: 1rpx;
							box-sizing: border-box;
							margin-right: 10rpx;
						}
					}
	
					.typeBookingTv {
						width: 130rpx;
						height: 60rpx;
						background: #E6A5B4;
						border-radius: 10rpx;
						color: #333;
						font-size: 28rpx;
						display: flex;
						align-items: center;
						justify-content: center;
					}
	
					.typeBookingTvTo {
						width: 130rpx;
						height: 60rpx;
						background: #00000000;
						border-radius: 10rpx;
						border: 1rpx solid #939393;
						color: #939393;
						font-size: 28rpx;
						display: flex;
						align-items: center;
						justify-content: center;
					}
				}
			}
		}
	}
	
	.listV {
		padding-left: 30rpx;
		margin-top: 30rpx;
	
		.scrV {
			width: 100%;
			white-space: nowrap;
			vertical-align: middle;
			overflow: hidden;
			height: 300rpx;
	
			.itemV {
				width: 210rpx;
				height: 300rpx;
				background: #E6A5B4;
				margin-right: 15rpx;
				display: inline-block;
				flex-direction: column;
				align-items: center;
	
	
				.itemBg {
					width: 210rpx;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
	
					.avatarIv {
						width: 100rpx;
						height: 100rpx;
						border-radius: 50%;
						margin-top: 30rpx;
					}
	
					.nameTv {
						font-size: 30rpx;
						color: #E8E8E8;
						margin-top: 10rpx;
					}
	
					.typeTv {
						margin-top: 10rpx;
						background: #FDDCE4;
						border-radius: 10rpx 0rpx 10rpx 0rpx;
						color: #9B9B9B;
						font-size: 22rpx;
						padding-left: 18rpx;
						padding-right: 18rpx;
						padding-top: 1rpx;
						padding-bottom: 1rpx;
						margin-left: 20rpx;
						margin-right: 20rpx;
						display: block;
						white-space: nowrap;
						text-overflow: ellipsis;
						overflow: hidden;
						width: fit-content;
						max-width: 180rpx;
						box-sizing: border-box;
					}
	
					.moneyTv {
						margin-top: 18rpx;
						font-size: 22rpx;
						color: #FFFFFF;
					}
				}
			}
		}
	}
	
	.itemCampV {
		width: 90%;
		background: #1F1F1F;
		border-radius: 10rpx;
		height: 280rpx;
		margin-bottom: 30rpx;
	
		.itemCampIv {
			width: 100%;
			height: 200rpx;
			background-color: antiquewhite;
			border-radius: 10rpx 10rpx 0rpx 0rpx;
		}
	
		.itemCampTv {
			width: 100%;
			height: 80rpx;
			font-size: 28rpx;
			color: #E8E8E8;
			display: block;
			white-space: nowrap;
			/* 过长部分不换行 */
			text-overflow: ellipsis;
			/* 过长部分展示省略号 */
			overflow: hidden;
			/* 隐藏过长部分 */
			margin-top: 10rpx;
		}
	}
</style>